
#include <assert.h>
#include "app_platform/cmd_obj.h"
#include "app_platform/cmd_obj_ext.h"
#include "app_platform/cntl_info.h"
#include "app_platform/intf_service_control.h"
#include "logservice/logger.h"
#include "cooperatorao_adaptor.h"
#include "cooperatorao_req_resp.h"


std::string g_scooperatoraoStandAlone;

///////////////////////
// class CCooperatorAoSvcFactory
int CCooperatorAoSvcFactory::init(void* pvParam)
{
	IUserDefineCntl* pCntl = reinterpret_cast<IUserDefineCntl*>(pvParam);
	assert(pCntl);
    pCntl->getConfig("StandAlone", g_scooperatoraoStandAlone);
         

	return CCooperatorAo::Initialize(pCntl);
}

int CCooperatorAoSvcFactory::CXYZTimerHandler::OnTimer(int iTimerId)
{
    assert(0);
	return 0;
}

int CCooperatorAoSvcFactory::fini(void* pvParam)
{
    return 0;
}

uint32_t CCooperatorAoSvcFactory::getCateId() const
{   
	//方法已废弃
    return 0;
}

IService* CCooperatorAoSvcFactory::createService(uint32_t dwcmdId)
{
    return (new CCooperatorAoService(dwcmdId));
}

void CCooperatorAoSvcFactory::getServiceType(ServiceTypeMap_T& mapSvcType)
{
	mapSvcType[COOPERATORAO_CHECKCOOPERATORPASSWD_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_DELETECOOPERATORMONITORMODEL_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_GETCOOPERATORBASEINFO_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_GETCOOPERATORBASEINFOLIST_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_GETCOOPERATORIDBYICSONID_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_GETCOOPERATORKEY_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_GETCOOPERATORLICENSE_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_GETCOOPERATORMONITORMODEL_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_GETCOOPERATORMONITORMODELLIST_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_LOGISTICSSETCOOPERATORPRO_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_SETCOOPERATORINFO_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_SETCOOPERATORPASSWD_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_UPDATECOOPERATORBASEINFO_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_UPDATECOOPERATORLICENSE_REQ_CMD_ID] = true;
	mapSvcType[COOPERATORAO_UPDATECOOPERATORMONITORMODEL_REQ_CMD_ID] = true;
}

////////////////////////
// class CCooperatorAoService
CCooperatorAoService::CCooperatorAoService(uint32_t dwcmdId) 
: m_dwcmdId(dwcmdId)
{
    enum DeployMethod method = DEPLOY_DETACH;
    if(!g_scooperatoraoStandAlone.empty() && g_scooperatoraoStandAlone != "0") // Stand-Alone
        method = DEPLOY_STANDALONE;
        
    m_pSvc = new CCooperatorAo(method);
}

void CCooperatorAoService::Reset() 
{ 
	m_pSvc -> Reset();
}
    
void CCooperatorAoService::getCmdIdRange(uint32_t& dwcmdIdBegin, uint32_t& dwcmdIdEnd) const 
{ 
    dwcmdIdBegin = m_dwcmdId;
    dwcmdIdEnd = m_dwcmdId;
} 
	
int CCooperatorAoService::Execute(CCmdObj& oCmd)
{
	switch(oCmd.getCmdId())
	{
	case COOPERATORAO_CHECKCOOPERATORPASSWD_REQ_CMD_ID:
        return CheckCooperatorPassWd(oCmd);
	case COOPERATORAO_DELETECOOPERATORMONITORMODEL_REQ_CMD_ID:
        return DeleteCooperatorMonitorModel(oCmd);
	case COOPERATORAO_GETCOOPERATORBASEINFO_REQ_CMD_ID:
        return GetCooperatorBaseInfo(oCmd);
	case COOPERATORAO_GETCOOPERATORBASEINFOLIST_REQ_CMD_ID:
        return GetCooperatorBaseInfoList(oCmd);
	case COOPERATORAO_GETCOOPERATORIDBYICSONID_REQ_CMD_ID:
        return GetCooperatorIdByIcsonId(oCmd);
	case COOPERATORAO_GETCOOPERATORKEY_REQ_CMD_ID:
        return GetCooperatorKey(oCmd);
	case COOPERATORAO_GETCOOPERATORLICENSE_REQ_CMD_ID:
        return GetCooperatorLicense(oCmd);
	case COOPERATORAO_GETCOOPERATORMONITORMODEL_REQ_CMD_ID:
        return GetCooperatorMonitorModel(oCmd);
	case COOPERATORAO_GETCOOPERATORMONITORMODELLIST_REQ_CMD_ID:
        return GetCooperatorMonitorModelList(oCmd);
	case COOPERATORAO_LOGISTICSSETCOOPERATORPRO_REQ_CMD_ID:
        return LogisticsSetCooperatorPro(oCmd);
	case COOPERATORAO_SETCOOPERATORINFO_REQ_CMD_ID:
        return SetCooperatorInfo(oCmd);
	case COOPERATORAO_SETCOOPERATORPASSWD_REQ_CMD_ID:
        return SetCooperatorPassWd(oCmd);
	case COOPERATORAO_UPDATECOOPERATORBASEINFO_REQ_CMD_ID:
        return UpdateCooperatorBaseInfo(oCmd);
	case COOPERATORAO_UPDATECOOPERATORLICENSE_REQ_CMD_ID:
        return UpdateCooperatorLicense(oCmd);
	case COOPERATORAO_UPDATECOOPERATORMONITORMODEL_REQ_CMD_ID:
        return UpdateCooperatorMonitorModel(oCmd);
	default:
		assert(0);
	}
	return 0;
}

int CCooperatorAoService::CheckCooperatorPassWd(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoCheckCooperatorPassWdReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoCheckCooperatorPassWdResp oResp;
	
    oResp.dwResult = m_pSvc->CheckCooperatorPassWd(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorId,
		oReq.cooperatorPassword,
		oReq.inReserve,
		oReq.errmsg,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::DeleteCooperatorMonitorModel(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoDeleteCooperatorMonitorModelReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoDeleteCooperatorMonitorModelResp oResp;
	
    oResp.dwResult = m_pSvc->DeleteCooperatorMonitorModel(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorId,
		oReq.modelId,
		oReq.inReserve,
		oReq.errmsg,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::GetCooperatorBaseInfo(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoGetCooperatorBaseInfoReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoGetCooperatorBaseInfoResp oResp;
	
    oResp.dwResult = m_pSvc->GetCooperatorBaseInfo(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorId,
		oReq.inReserve,
		oReq.errmsg,
		oReq.cooperatorBaseInfoPo,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.cooperatorBaseInfoPo = oReq.cooperatorBaseInfoPo;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::GetCooperatorBaseInfoList(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoGetCooperatorBaseInfoListReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoGetCooperatorBaseInfoListResp oResp;
	
    oResp.dwResult = m_pSvc->GetCooperatorBaseInfoList(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorId,
		oReq.inReserve,
		oReq.errmsg,
		oReq.cooperatorBaseInfoPo,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.cooperatorBaseInfoPo = oReq.cooperatorBaseInfoPo;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::GetCooperatorIdByIcsonId(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoGetCooperatorIdByIcsonIdReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoGetCooperatorIdByIcsonIdResp oResp;
	
    oResp.dwResult = m_pSvc->GetCooperatorIdByIcsonId(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.icsonId,
		oReq.inReserve,
		oReq.errmsg,
		oReq.cooperatorId,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.cooperatorId = oReq.cooperatorId;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::GetCooperatorKey(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoGetCooperatorKeyReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoGetCooperatorKeyResp oResp;
	
    oResp.dwResult = m_pSvc->GetCooperatorKey(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorId,
		oReq.inReserve,
		oReq.errmsg,
		oReq.sCooperatorKey,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.sCooperatorKey = oReq.sCooperatorKey;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::GetCooperatorLicense(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoGetCooperatorLicenseReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoGetCooperatorLicenseResp oResp;
	
    oResp.dwResult = m_pSvc->GetCooperatorLicense(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorId,
		oReq.licenseType,
		oReq.inReserve,
		oReq.errmsg,
		oReq.cooperatorLicensePo,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.cooperatorLicensePo = oReq.cooperatorLicensePo;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::GetCooperatorMonitorModel(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoGetCooperatorMonitorModelReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoGetCooperatorMonitorModelResp oResp;
	
    oResp.dwResult = m_pSvc->GetCooperatorMonitorModel(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorId,
		oReq.modelId,
		oReq.inReserve,
		oReq.errmsg,
		oReq.CooperatorMonitorModelPo,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.CooperatorMonitorModelPo = oReq.CooperatorMonitorModelPo;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::GetCooperatorMonitorModelList(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoGetCooperatorMonitorModelListReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoGetCooperatorMonitorModelListResp oResp;
	
    oResp.dwResult = m_pSvc->GetCooperatorMonitorModelList(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorId,
		oReq.inReserve,
		oReq.errmsg,
		oReq.CooperatorMonitorModelPo,
		oReq.rulesruleJson,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.CooperatorMonitorModelPo = oReq.CooperatorMonitorModelPo;
	oResp.rulesruleJson = oReq.rulesruleJson;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::LogisticsSetCooperatorPro(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoLogisticsSetCooperatorProReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoLogisticsSetCooperatorProResp oResp;
	
    oResp.dwResult = m_pSvc->LogisticsSetCooperatorPro(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.option,
		oReq.cooperatorProPo,
		oReq.inReserve,
		oReq.errmsg,
		oReq.cooperatorBaseInfoPo,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.cooperatorBaseInfoPo = oReq.cooperatorBaseInfoPo;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::SetCooperatorInfo(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoSetCooperatorInfoReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoSetCooperatorInfoResp oResp;
	
    oResp.dwResult = m_pSvc->SetCooperatorInfo(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.option,
		oReq.cooperatorSetPo,
		oReq.inReserve,
		oReq.errmsg,
		oReq.cooperatorBaseInfoPo,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.cooperatorBaseInfoPo = oReq.cooperatorBaseInfoPo;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::SetCooperatorPassWd(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoSetCooperatorPassWdReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoSetCooperatorPassWdResp oResp;
	
    oResp.dwResult = m_pSvc->SetCooperatorPassWd(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorId,
		oReq.cooperatorOldPassword,
		oReq.cooperatorNewPassword,
		oReq.inReserve,
		oReq.errmsg,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::UpdateCooperatorBaseInfo(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoUpdateCooperatorBaseInfoReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoUpdateCooperatorBaseInfoResp oResp;
	
    oResp.dwResult = m_pSvc->UpdateCooperatorBaseInfo(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorBaseInfoPo,
		oReq.inReserve,
		oReq.errmsg,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::UpdateCooperatorLicense(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoUpdateCooperatorLicenseReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoUpdateCooperatorLicenseResp oResp;
	
    oResp.dwResult = m_pSvc->UpdateCooperatorLicense(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.cooperatorLicensePo,
		oReq.inReserve,
		oReq.errmsg,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


int CCooperatorAoService::UpdateCooperatorMonitorModel(CCmdObj& oCmd)
{
	char* pBuf = NULL; uint32_t nLen = 0;
    oCmd.getBuffer(pBuf, nLen);
    CByteStreamNetwork bs(pBuf, nLen);
    bs.isStoring(false);
    bs.setVersion(oCmd.getVersion());
    CCooperatorAoUpdateCooperatorMonitorModelReq oReq;
    if(!oReq.Serialize(bs))
    {
        m_sLastErrMsg = "Req.Serialize(bs) failed.";
        return -1;
    }

    CCntlInfo oCntlInfo;
    oCntlInfo.setCntl(reinterpret_cast<void*>(m_pSvcCntl));
    oCntlInfo.setOperatorUin(oCmd.getOperatorUin());
	oCntlInfo.setOperatorClientIP(oCmd.getOperatorClientIP());
	oCntlInfo.setOperatorKey(oCmd.getOperatorKey());
    oCntlInfo.setRouteKey(oCmd.getUin());
    oCntlInfo.setCmdId(oCmd.getCmdId());
    oCntlInfo.setNetioClientIP(oCmd.getNetioClientIP());
	oCntlInfo.setSerialNo(oCmd.getSerialNo());
	oCntlInfo.setPkgTimestamp(oCmd.getPkgTimestamp());
	
	if (oCmd.getVersion() == 3)
    {
        CCmdObjExt& oCmdExt = dynamic_cast<CCmdObjExt&>(oCmd);
        oCntlInfo.setAppId(oCmdExt.getReserve1());
        oCntlInfo.setDomainId(oCmdExt.getReserve2());
    }
	
	CCooperatorAoUpdateCooperatorMonitorModelResp oResp;
	
    oResp.dwResult = m_pSvc->UpdateCooperatorMonitorModel(
		oCntlInfo,
		oReq.machineKey,
		oReq.source,
		oReq.sceneId,
		oReq.CooperatorMonitorModelPo,
		oReq.inReserve,
		oReq.errmsg,
		oReq.outReserve
    );
	oResp.errmsg = oReq.errmsg;
	oResp.outReserve = oReq.outReserve;

    return m_pSvcCntl->putSvcObj(&oResp, oResp.dwResult);
}


#include "svc_main.h"

IServiceFactory* GetServiceFactory(void)
{
    return CSvcFactorySingleton::Instance();
}
